import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/resources/colours.dart';

import 'base/wqs_text.dart';

class SelectBottomSheet extends StatelessWidget {
  final List<String> titles;
  final List<Widget>? items;
  final String? top;
  final int? select;

  const SelectBottomSheet(
    this.titles, {
    super.key,
    this.top,
    this.items,
    this.select,
  });

  @override
  Widget build(BuildContext context) {
    return BottomSheet(
      enableDrag: false,
      clipBehavior: Clip.hardEdge,
      shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(10), topRight: Radius.circular(10))),
      onClosing: () {},
      builder: (context) {
        return Container(
          color: Colours.greyFD,
          child: SafeArea(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                if (top != null)
                  Container(
                    height: 52,
                    color: Colours.greyFD,
                    child: Center(
                        child:
                            QsText(top!, fontSize: 17, color: Colours.grey99)),
                  ),
                MediaQuery.removePadding(
                  context: context,
                  removeTop: true,
                  removeBottom: true,
                  child: ListView.separated(
                    shrinkWrap: true,
                    itemCount: titles.length,
                    itemBuilder: (context, index) {
                      return GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          navigator?.pop(index);
                        },
                        child: Row(
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Container(
                              height: 52,
                              color: Colours.greyFD,
                              child: Center(
                                  child: QsText(titles[index],
                                      fontSize: 17,
                                      color: select == index
                                          ? Colours.main
                                          : Colours.black292D32)),
                            ),
                            if (items?[index] != null) ...[
                              Container(width: 2),
                              items?[index] ?? Container()
                            ]
                          ],
                        ),
                      );
                    },
                    separatorBuilder: (context, index) {
                      return Container(
                        width: double.infinity,
                        height: 0.5,
                        color: Colours.greyEE,
                      );
                    },
                  ),
                ),
                Container(
                  height: 10,
                  width: double.infinity,
                  color: Colours.greyF7,
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: navigator?.pop,
                  child: Container(
                    height: 52,
                    color: Colours.greyFD,
                    child: const Center(
                        child: QsText('取消',
                            fontSize: 17, color: Colours.black292D32)),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
